import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";

class AssociatedBlock extends StatefulWidget {
  final Widget icon;
  final String title;
  final bool? disabled;
  final void Function()? onTap;
  const AssociatedBlock({super.key, required this.icon, required this.title, this.onTap, this.disabled});

  @override
  State<StatefulWidget> createState() => _AssociatedBlockState();

}

class _AssociatedBlockState extends State<AssociatedBlock> {
  bool _disabled = false;

  @override
  void initState() {
    setState(() {
      _disabled = widget.disabled ?? false;
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: _disabled ? () {
        Stacker.pop();
      } : widget.onTap,
      child: Container(
        height: 60,
        decoration: BoxDecoration(
            color: _disabled ? ThemeVars.colorBackground : ThemeVars.colorPrimaryLight,
            borderRadius: BorderRadius.all(Radius.circular(5))
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            widget.icon,
            const SizedBox(width: 12,),
            Text(widget.title, style: TextStyle(color: _disabled ? ThemeVars.colorTextTer : ThemeVars.colorText),)
          ],
        ),
      )
    );
  }
}